package gcj2008.round1a;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import common.AbstractRunner;

public class B extends AbstractRunner {
	
	class Customer {
		Set<Integer> unmalted = new HashSet<Integer>();
		int malted = -1;
		boolean satisfied = false;
	}
	
	public void handleCase(int caseNumber) throws Exception {
		int n = scanner.nextInt();
		int m = scanner.nextInt();
		ArrayList<Integer> al;
		Customer[] cust = new Customer[m];
		
		for (int i=0; i<m; i++) {
			int t = scanner.nextInt();
			cust[i] = new Customer();
			for (int j=0; j<t; j++) {
				int shake = scanner.nextInt() - 1;
				int malted = scanner.nextInt();
				if (malted == 1) {
					cust[i].malted = shake;
				} else {
					cust[i].unmalted.add(shake);
				}
			}	
		}
		
		int unsatisfied = m;
		int[] res = new int[n];  
		while (unsatisfied != 0) {			
			int idx = -1;
			for (int i=0; i<m; i++) {
				if ((!cust[i].satisfied) && cust[i].unmalted.size() == 0) {
					idx = i;
					break;
				}
			}
			if (idx == -1) break;
			if (cust[idx].malted == -1) {
				out.write("IMPOSSIBLE\r\n");
				return;
			}
			res[cust[idx].malted] = 1;
			
			for (int i=0; i<m; i++) {
				if (!cust[i].satisfied) {			
					if (cust[i].malted == cust[idx].malted) {
						cust[i].satisfied = true;
						unsatisfied --;
					}
					cust[i].unmalted.remove(cust[idx].malted);
				}
			}	
		}
		
		out.write(Integer.toString(res[0]));
		for (int i=1; i<n; i++) out.write(" "+Integer.toString(res[i]));
		out.write("\r\n");
	}

	public static void main(String[] args) throws Exception {
		new B().init(SIZE.large).execute();
	}
		
}
